# coding=utf-8
from jdcloud_sdk.core.credential import Credential
from jdcloud_sdk.services.sms.client.SmsClient import SmsClient
from jdcloud_sdk.services.sms.apis.BatchSendRequest import BatchSendParameters, BatchSendRequest
from jdcloud_sdk.services.sms.apis.StatusReportRequest import StatusReportParameters, StatusReportRequest
from jdcloud_sdk.services.sms.apis.ReplyRequest import ReplyParameters, ReplyRequest

# 地域信息不用修改
regionId = 'cn-north-1'
# 请填写用户aksk （应用管理-概览 页面可以查看自己aksk）
access_key = 'JDC_946234AA9FA4F276892E94B780C5'
secret_key = '2B8668593D75AB49ED9828FED8948812'
credential = Credential(access_key, secret_key)
client = SmsClient(credential)


# 发送
def testBatchSendMsg(phone):
    try:
        # 设置模板Id
        templateId = 'bm_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        # 设置签名Id
        signId = 'qm_54a8185072424d9fbafc7607a107c9a2'
        # 设置发送手机号
        phoneList = phone
        parameters = BatchSendParameters(regionId=regionId, templateId=templateId,
                                         signId=signId, phoneList=phoneList)
        # 设置模板参数， 非必填
        params = []
        parameters.setParams(params=params)
        request = BatchSendRequest(parameters)
        resp = client.send(request)
        if resp.error is not None:
            print(resp.error.code, resp.error.message)
        print(resp.result)
    except Exception as e:
        print(e)
        # 错误处理


# # 查询状态报告
# def testStatusReport():
#     try:
#         # 设置序列号。序列号从下发接口response中获取
#         sequenceNumber = '1227185xxxxxxxxxxxxxx'
#         parameters = StatusReportParameters(regionId=regionId, sequenceNumber=sequenceNumber)
#         # 设置需要获取回执的手机号码列表，非必传
#         # phoneList = [ ]
#         # parameters.setPhoneList(phoneList=phoneList)
#         request = StatusReportRequest(parameters)
#
#         resp = client.send(request)
#         if resp.error is not None:
#             print(resp.error.code, resp.error.message)
#         print(resp.result)
#     except Exception as e:
#         print(e)
#
#
# # 查询回复信息
# def testReply():
#     try:
#         # 设置应用Id
#         appId = '22ed9c2xxxxxxxxxxxxxxxxxxx'
#         # 设置查询时间
#         dataDate = 'xxxx-xx-xx'
#         parameters = ReplyParameters(regionId=regionId, appId=appId, dataDate=dataDate)
#         # 设置查询手机号
#         phoneList = []
#         parameters.setPhoneList(phoneList=phoneList)
#         request = ReplyRequest(parameters)
#         resp = client.send(request)
#         if resp.error is not None:
#             print(resp.error.code, resp.error.message)
#         print(resp.result)
#     except Exception as e:
#         print(e)


if __name__ == '__main__':
    # 发送短信
    testBatchSendMsg()
    # 查询状态报告
    # testStatusReport()
    # 查询回复信息
    # testReply()
